<?php
if(empty($_REQUEST['submit'])) {
	$maint_log_subhead = $maint_log_title = "Add a Project";
	require_once("include_functions.php");
	require_once("include_header.php");
?>

<?php
$sql = "SELECT * FROM schedule";
if($result = mysql_query($sql)) echo mysql_error();
$schedule = mysql_fetch_array($result);
?>

<div id="content">
	<form action="manage_schedule.php" method="post">
	<div class="form-box">
		<div class="form-title">Update the Schedule</div>
		<div style="float:left;">
			<span class="form-title">Monday</span>
			<label for="mon-am">AM</label>
			<input type="checkbox" name="mon-am" id="mon-am" <?php printf('%s', ($schedule['mon-am']) ? 'checked="checked"' : '') ?> />
			<label for="mon-pm">PM</label>
			<input type="checkbox" name="mon-pm" id="mon-pm" <?php printf('%s', ($schedule['mon-pm']) ? 'checked="checked"' : '') ?> />
		</div>
		<div style="float:left;">
			<span class="form-title">Tuesday</span>
			<label for="tue-am">AM</label>
			<input type="checkbox" name="tue-am" id="tue-am" <?php printf('%s', ($schedule['tue-am']) ? 'checked="checked"' : '') ?> />
			<label for="tue-pm">PM</label>
			<input type="checkbox" name="tue-pm" id="tue-pm" <?php printf('%s', ($schedule['tue-pm']) ? 'checked="checked"' : '') ?> />
		</div>
		<div style="float:left;">
			<span class="form-title">Wednesday</span>
			<label for="wed-am">AM</label>
			<input type="checkbox" name="wed-am" id="wed-am" <?php printf('%s', ($schedule['wed-am']) ? 'checked="checked"' : '') ?> />
			<label for="wed-pm">PM</label>
			<input type="checkbox" name="wed-pm" id="wed-pm" <?php printf('%s', ($schedule['wed-pm']) ? 'checked="checked"' : '') ?> />
		</div>
		<div style="float:left;">
			<span class="form-title">Thursday</span>
			<label for="thu-am">AM</label>
			<input type="checkbox" name="thu-am" id="thu-am" <?php printf('%s', ($schedule['thu-am']) ? 'checked="checked"' : '') ?> />
			<label for="thu-pm">PM</label>
			<input type="checkbox" name="thu-pm" id="thu-pm" <?php printf('%s', ($schedule['thu-pm']) ? 'checked="checked"' : '') ?> />
		</div>
		<div style="float:left;">
			<span class="form-title">Friday</span>
			<label for="fri-am">AM</label>
			<input type="checkbox" name="fri-am" id="fri-am" <?php printf('%s', ($schedule['fri-am']) ? 'checked="checked"' : '') ?> />
			<label for="fri-pm">PM</label>
			<input type="checkbox" name="fri-pm" id="fri-pm" <?php printf('%s', ($schedule['fri-pm']) ? 'checked="checked"' : '') ?> />
		</div>
		<div class="buttons" style="clear:both;">
			<input type="submit" name="submit" value="submit">
		</div>
	</form>
	</div>
</div>

<?php
require_once("include_footer.php");
?>

<?php
} else {

	require_once('include_db.php');
	require_once('include_config.php');
	$mon_am = (array_key_exists('mon-am', $_REQUEST)) ? 'TRUE' : 'FALSE' ;
	$mon_pm = (array_key_exists('mon-pm', $_REQUEST)) ? 'TRUE' : 'FALSE' ;
	$tue_am = (array_key_exists('tue-am', $_REQUEST)) ? 'TRUE' : 'FALSE' ;
	$tue_pm = (array_key_exists('tue-pm', $_REQUEST)) ? 'TRUE' : 'FALSE' ;
	$wed_am = (array_key_exists('wed-am', $_REQUEST)) ? 'TRUE' : 'FALSE' ;
	$wed_pm = (array_key_exists('wed-pm', $_REQUEST)) ? 'TRUE' : 'FALSE' ;
	$thu_am = (array_key_exists('thu-am', $_REQUEST)) ? 'TRUE' : 'FALSE' ;
	$thu_pm = (array_key_exists('thu-pm', $_REQUEST)) ? 'TRUE' : 'FALSE' ;
	$fri_am = (array_key_exists('fri-am', $_REQUEST)) ? 'TRUE' : 'FALSE' ;
	$fri_pm = (array_key_exists('fri-pm', $_REQUEST)) ? 'TRUE' : 'FALSE' ;

	$sql = "UPDATE schedule SET ".
			"`mon-am` = $mon_am , ".
			"`mon-pm` = $mon_pm , ".
			"`tue-am` = $tue_am , ".
			"`tue-pm` = $tue_pm , ".
			"`wed-am` = $wed_am , ".
			"`wed-pm` = $wed_pm , ".
			"`thu-am` = $thu_am , ".
			"`thu-pm` = $thu_pm , ".
			"`fri-am` = $fri_am , ".
			"`fri-pm` = $fri_pm;";
	
	if($result = mysql_query($sql)) echo mysql_error();
	// send user back to homepage
	header("Location: http://" . $maint_log_config['address'] . "/index.php");
}
?>


